package com.whnk.attendance.controller;

import com.whnk.attendance.service.IPmProLevelService;
import com.whnk.attendance.vo.PmProListVo;
import com.whnk.attendance.vo.PmProQueryVo;
import com.whnk.attendance.vo.PmProUpdateVo;
import com.whnk.common.core.utils.poi.ExcelUtil;
import com.whnk.common.core.web.controller.BaseController;
import com.whnk.common.core.web.domain.AjaxResult;
import com.whnk.common.core.web.page.TableDataInfo;
import com.whnk.common.log.annotation.Log;
import com.whnk.common.log.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 项目级别列表Controller
 *
 * @author whnk
 * @date 2021-11-17
 */
@Api(tags = "项目级别列表Controller")
@RestController
@RequestMapping("/pmProLevel")
public class PmProLevelController extends BaseController
{
    @Autowired
    private IPmProLevelService pmProLevelService;

    /**
     * 查询项目级别列列表
     */
    @ApiOperation(value = "分页查询项目级别列列表")
    //@PreAuthorize(hasPermi = "attendance:level:list")
    @GetMapping("/list")
    public TableDataInfo list(PmProQueryVo pmProQueryVo)
    {
        startPage();
        return pmProLevelService.selectPmProLevelListTable(pmProQueryVo);
    }

    /**
     * 导入项目级别列列表
     */
    @ApiOperation(value = "导入项目级别列列表")
    @PostMapping("/import")
    public AjaxResult imports(@RequestPart("excelFile") MultipartFile file,boolean updateSupport) throws Exception {
        ExcelUtil<PmProListVo> util = new ExcelUtil<>(PmProListVo.class);
        List<PmProListVo> pmProListVos = util.importExcel(file.getInputStream());
        if(CollectionUtils.isEmpty(pmProListVos)){
            return AjaxResult.error("导入不能为空");
        }
        String s = pmProLevelService.pmProLeverUpload(pmProListVos, updateSupport);
        return AjaxResult.success(s);
    }

    /**
     * 导出项目级别列列表
     */
    @ApiOperation(value = "导出项目级别列列表")
    //@PreAuthorize(hasPermi = "attendance:level:export")
    @Log(title = "项目级别列", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PmProQueryVo pmProQueryVo1) throws IOException
    {

        List<PmProListVo> list = pmProLevelService.selectPmProLevelList(pmProQueryVo1);
        ExcelUtil<PmProListVo> util = new ExcelUtil<PmProListVo>(PmProListVo.class);
        util.exportExcel(response, list, "项目级别列数据");
    }

    /**
     * 获取项目级别列详细信息
     */
    @ApiOperation(value = "根据逻辑主键获取项目级别列详细信息")
   // @PreAuthorize(hasPermi = "attendance:level:query")
    @GetMapping(value = "/{proId}")
    public AjaxResult getInfo(@ApiParam(value = "项目级别列proId",example = "1",required = true) @PathVariable("proId") Long proId)
    {
        return AjaxResult.success(pmProLevelService.selectPmProLevelByProId(proId));
    }

    /**
     * 新增项目级别列
     */
    @ApiOperation(value = "新增项目级别列")
   // @PreAuthorize(hasPermi = "attendance:level:add")
    @Log(title = "项目级别列", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PmProUpdateVo pmProUpdateVo)
    {
        return toAjax(pmProLevelService.insertPmProLevel(pmProUpdateVo));
    }

    /**
     * 修改项目级别列
     */
    @ApiOperation(value = "修改项目级别列")
   // @PreAuthorize(hasPermi = "attendance:level:edit")
    @Log(title = "项目级别列", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PmProUpdateVo pmProUpdateVo)
    {
        return toAjax(pmProLevelService.updatePmProLevel(pmProUpdateVo));
    }

    /**
     * 删除项目级别列
     */
    @ApiOperation(value = "根据主键集合删除项目级别列")
   // @PreAuthorize(hasPermi = "attendance:level:remove")
    @Log(title = "项目级别列", businessType = BusinessType.DELETE)
	@DeleteMapping("/{proIds}")
    public AjaxResult remove(@ApiParam(value = "主键集合",example = "1,2,3",required = true) @PathVariable Long[] proIds)
    {
        return toAjax(pmProLevelService.deletePmProLevelByProIds(proIds));
    }
}
